<?php
class UserIdentity extends CUserIdentity {
	/**
	 * User's attributes
	 * @var array
	 */
	public $user;
	public $_id;
	public function authenticate() {
		$admin_model = new Admin ( );
		$user = $admin_model->findByAttributes ( array (
			
			"passport" => $this->username 
		) );
		if ($user === null)
			$this->errorCode = self::ERROR_USERNAME_INVALID;
		else if ($user->pwd !== md5 ( $this->password ))
			$this->errorCode = self::ERROR_PASSWORD_INVALID;
		else {
			$this->_id = $user->id;
			$this->username = $user->passport;
			$this->setUser ( $user );
			$this->errorCode = self::ERROR_NONE;
		}
		unset ( $user );
		return $this->errorCode==self::ERROR_NONE;
	}
	public function getUser() {
		return $this->user;
	}
	
	public function setUser(CActiveRecord $user) {
		$this->user = $user->attributes;
	}

}
?>